import { _decorator, Component, Node, Collider2D, Contact2DType, IPhysics2DContact } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('GroundController')
export class GroundController extends Component {
    
    start() {
        // 获取碰撞器组件
        const collider = this.getComponent(Collider2D);
        if (collider) {
            // 注册碰撞事件监听
            collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
            collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
        }
    }

    // 碰撞开始回调
    private onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        console.log('碰撞开始：', otherCollider.node.name);
        // 这里可以添加碰撞后的处理逻辑
    }

    // 碰撞结束回调
    private onEndContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        console.log('碰撞结束：', otherCollider.node.name);
        // 这里可以添加碰撞结束后的处理逻辑
    }

    update(deltaTime: number) {
        // 每帧更新逻辑
    }
}
